﻿@using viBook.Common
@using viBook.Models
@{
    ViewBag.Title = "Home Page";
    var listCategories = ViewBag.ListCategories as IEnumerable<Category>;
    var listMostPopularTags = ViewBag.ListMostPopularTags as IEnumerable<ContentTag>;
    var listMostPopularBook = ViewBag.ListMostPopularBook as IEnumerable<Book>;
    var listMostPopularUser = ViewBag.ListMostPopularUser as IEnumerable<User>;
    var u = (User)HttpContext.Current.Session["user"];
    var avatarUrl = (u == null || String.IsNullOrEmpty(u.AvatarUrl)) ? Url.Content("~/Content/default_avatar.jpg") : u.AvatarUrl;
}
<div id="non-logged-blurb" class="group">
    <div class="full group">
        <h1 class="compact">
            @if(u==null){
                <strong>What are you reading now?</strong> <span>Vibook will give you any book you want.</span>
                <a href="../Account/Register" class="tagline-action">Sign up as a member</a>
            }
            else{
                <strong>Hi, @u.DisplayName</strong>
                <span>. What are you reading now? </span>}
        </h1>
    </div>
</div>
<div id="main">
    <div data-bind='template: { name: "categories-template", foreach: listCategories}'
        id="list-categories">
    </div>
</div>
<div id="secondary">
  @Html.Partial("SecondaryTemplate")
</div>
<!-- /secondary -->
<script id='categories-template' type="text/html">
    <ul class="tabs">
        <li class="active">
            <a data-bind="attr: { href: '/categories/details/'+ categoryId}"><span data-bind="text: categoryName"></span></a>
        </li></ul>
    <ol class="dribbbles group">
        <div data-bind='template: { name: "book-template", foreach: listBook }'
             id="uploaded-book">
        </div>
    </ol>
</script>
@Html.Partial("BookControlTemplate")
<script type="text/javascript">
 
 function Category(id, name, listBook) {
     return {
         categoryId: id,
         categoryName: name,
         listBook: listBook
     };
 } 


   var  categories = @CustomHelpers.CategoriesToJavaScriptConverter(listCategories.Take(Constant.MaximunBookPerPage).ToList()) ,
     listTags = @CustomHelpers.ContentTagsToJavaScriptConverter(listMostPopularTags.ToList()) ,
     listshortBook = @CustomHelpers.BooksToJavaScriptConverter(listMostPopularBook.ToList()) ,
     listUsers = @CustomHelpers.UserToJavaScriptConverter(listMostPopularUser.ToList()) ,
     viewmodel = {
         listCategories: ko.observableArray(categories),
         listTags: ko.observableArray(listTags),
         listShortBook: ko.observableArray(listshortBook),
         listUsers: ko.observableArray(listUsers)
     };
 ko.applyBindings(viewmodel);
</script>
